<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>config-conn-common</title>
    
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/form.jsp"%>
	<script type="text/javascript">
		 function test(){
			 $.ajax({
				   type: "POST", 
				   url: "${pageContext.request.contextPath}/config/config-conn!allProbe.action", //请求的action
				   data: '', //传的参数
				   dataType: 'json',
				   success: function(data){ //结果
					   var obj= document.getElementById("result");
					   obj.length=0;
					   if(data.length == 0){
						   obj.options[0]=new Option("没有正在运行的probe!");
					   }else{
						   for(var i = 0; i < data.length; i++){
							   obj.options[i]=new Option(data[i].name+"   测试中，请等待...",data[i].id);
						   }
						   var num = 0;
						   connTest(data,num);
					   }
				   }
			 });
		 }
		 function connTest(probe,num){
			  $.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/config/config-conn!test.action", //请求的action
					data : "id=" + '${id}'+"&type="+'${type}'+"&propId="+probe[num].id, //传的参数
					dataType : 'json',
					success : function(data) { //结果
						var obj= document.getElementById("result");
						if(data.flag == "true"){
							obj.options[num].text ="通过	"+probe[num].name+"	与	"+data.ip+"	连接成功！";
						}else{
							obj.options[num].text ="通过	"+probe[num].name+"	与	"+data.ip+"	连接失败！";
						}
						num++;
						if(num < probe.length){
							connTest(probe,num);
						}
					}
			});
	  }
		function closewin(){
	  		getTopWin(window).closejBox("config-conn");
  		}
		 $(function(){

		 });
	</script>
  </head>
  
  <body class="padding-8">
    	<form action="" id="myform">
    		<table class="table_eidt" style="margin-top:9px;" id="testTable">
    			<tr>
	    			<td class="td_left" width="100px">测试结果</td>
	    			<td class="td_right">
	    				<select multiple="multiple" id="result" style="width:430px; height: 150px;border-style:solid; border-width:1px; border-color:#cccccc;overflow: auto;  disabled="disabled"></select>
	    			</td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:9px;">
	    		<input type="button" id="button" name="button" value="测试" class="btn-4" onclick="test();">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    	</form>
  </body>
</html>
